package com.homedo.odin.solution.util;

import com.homedo.core.common.util.NumberHelper;
import com.homedo.odin.solution.contract.pc.SpecificationAddPcReq;
import com.homedo.odin.solution.contract.pc.SpecificationEditPcReq;
import com.homedo.odin.solution.model.dto.SpecificationListResponseBean;
import com.homedo.odin.solution.model.entity.Specification;
import org.apache.commons.lang3.StringUtils;

/**
 * @author: zhaoxudong
 * @date: 2018/4/10 18:04
 * @Description:
 */
public class SpecificationConvertUtils {

    public static void convert(Specification specification, SpecificationListResponseBean specificationResponse) {
        if (specification == null || specificationResponse == null) {
            return;
        }
        specificationResponse.setSpecificationId(specification.getSpecificationId());
        specificationResponse.setSpecificationIdStr(specification.getSpecificationId().toString());
        specificationResponse.setSpecificationName(specification.getSpecificationName());
        specificationResponse.setSpecificationStatus(specification.getSpecificationStatus());
        specificationResponse.setStatus(specification.getStatus());
        specificationResponse.setMatchPic(specification.getMatchPic());
        specificationResponse.setZone(specification.getZone());
        specificationResponse.setPublishDate(specification.getShelveTime());
        specificationResponse.setImplementData(specification.getImplementData());
        specificationResponse.setDownoadCount(specification.getDownoadCount());
        specificationResponse.setLikeCount(specification.getLikeCount());
        specificationResponse.setPageView(specification.getPageView());
        specificationResponse.setCollectCount(specification.getCollectCount());
        specificationResponse.setCreateTime(specification.getCreateTime());
        specificationResponse.setAttachment(specification.getAttachment());
        specificationResponse.setFirstClassify(specification.getFirstClassify());
        specificationResponse.setIntroduction(specification.getIntroduction());
    }

    public static boolean validate(SpecificationAddPcReq specificationAddBean) {
        if (!NumberHelper.validatePositive(specificationAddBean.getUserId()) ||
                !NumberHelper.validatePositive(specificationAddBean.getFirstClassify()) ||
                !NumberHelper.validatePositive(specificationAddBean.getSecondClassify()) ||
                StringUtils.isEmpty(specificationAddBean.getSpecificationName())) {
            return false;
        }
        return true;
    }

    public static void convert(Specification specification, SpecificationAddPcReq specificationAddBean) {
        if (specification == null || specificationAddBean == null) {
            return;
        }
        specification.setAttachment(specificationAddBean.getAttachment());
        specification.setAuthor(specificationAddBean.getAuthor());
        specification.setCharges(specificationAddBean.getCharges());
        specification.setCode(specificationAddBean.getCode());
        specification.setFirstClassify(specificationAddBean.getFirstClassify());
        specification.setImplementData(specificationAddBean.getImplementData());
        specification.setIntroduction(specificationAddBean.getIntroduction());
        specification.setMainEditor(specificationAddBean.getMainEditor());
        specification.setMatchPic(specificationAddBean.getMatchPic());
        specification.setOldCode(specificationAddBean.getOldCode());
        specification.setPublishDate(specificationAddBean.getPublishDate());
        specification.setPublishDept(specificationAddBean.getPublishDept());
        specification.setSecondaryEditor(specificationAddBean.getSecondaryEditor());
        specification.setSecondClassify(specificationAddBean.getSecondClassify());
        specification.setSpecificationName(specificationAddBean.getSpecificationName());
        specification.setUserId(specificationAddBean.getUserId());
        specification.setUserName(specificationAddBean.getUserName());
        specification.setZone(specificationAddBean.getZone());
    }

    public static void convert(Specification specification, SpecificationEditPcReq specificationEditBean) {
        if (specification == null || specificationEditBean == null) {
            return;
        }
        specification.setSpecificationId(Long.parseLong(specificationEditBean.getSpecificationId()));
        specification.setAttachment(specificationEditBean.getAttachment());
        specification.setAuthor(specificationEditBean.getAuthor());
        specification.setCharges(specificationEditBean.getCharges());
        specification.setCode(specificationEditBean.getCode());
        specification.setFirstClassify(specificationEditBean.getFirstClassify());
        specification.setImplementData(specificationEditBean.getImplementData());
        specification.setIntroduction(specificationEditBean.getIntroduction());
        specification.setMainEditor(specificationEditBean.getMainEditor());
        specification.setMatchPic(specificationEditBean.getMatchPic());
        specification.setOldCode(specificationEditBean.getOldCode());
        specification.setPublishDate(specificationEditBean.getPublishDate());
        specification.setPublishDept(specificationEditBean.getPublishDept());
        specification.setSecondaryEditor(specificationEditBean.getSecondaryEditor());
        specification.setSecondClassify(specificationEditBean.getSecondClassify());
        specification.setSpecificationName(specificationEditBean.getSpecificationName());
        specification.setZone(specificationEditBean.getZone());

    }
}
